#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
const int MAXN=100086;
int i,j,n,m,f[MAXN][2];
string s,w_c;
char str[MAXN],first[3]={'(','+','*'};
stack<char> op;
int OPS(char a)
{
	int i;
	for(i=0;i<3;i++)if(a==first[i])return i;
	return -1;
}
inline void Change()
{
	int i;
	char t;
	for(i=0;i<n;i++)
	{
		if(str[i] == '(') s.push_back(str[i]); 
		else if(str[i] == ')' && str[i-1] != ')') s+="_)";
		else if(str[i]!=')' && str[i-1] != ')')
		{
			s.push_back('_');
			s.push_back(str[i]);
		}
		else s.push_back(str[i]);  
	}
	if(s.at(s.size()-1)!=')') s.push_back('_');
	for(i=0;i<s.size();i++)
	{
		t=s.at(i);
		if(t=='_')w_c.push_back(t);
		else
		{
			if(t!=')')
			{
				if(t=='(')op.push(t);
				else
				{
					if(op.empty())op.push(t);
					else
					{
						while((!op.empty())&& OPS(op.top())>=OPS(t))
							w_c.push_back(op.top()),op.pop();
						op.push(t);
					}
				}
			}
			else
			{
				while((!op.empty()) && op.top()!='(')
					w_c.push_back(op.top()),op.pop();
				op.pop();
			}
		}  
	}	
	while(!op.empty())
		w_c.push_back(op.top()),op.pop();
}
void work()
{
	size_t i,top(0);
	size_t l=w_c.size();
	for(i=0;i<l;i++)
	{
		if(w_c[i]=='_')f[top][0]=f[top][1]=1,top++;
		else
		{
			--top;
			switch(w_c[i])
			{
				case '+':
				{
					f[top-1][1] = (f[top][0] * f[top-1][1] + f[top][1] * f[top-1][0] + f[top][1] * f[top-1][1])%10007;
					f[top-1][0] = (f[top][0] * f[top-1][0]) % 10007; 
					break;
				}
				case '*':
				{
					f[top-1][0] = (f[top][0] * f[top-1][1] + f[top][1] * f[top-1][0] + f[top][0] * f[top-1][0])%10007;
					f[top-1][1] = (f[top][1] * f[top-1][1]) % 10007;
					break;
				}
			}
		}
	}
	printf("%d",f[top-1][0]);
}
int main(){
	scanf("%d",&n);
	scanf("%s",str);
	Change(); 
	work();
	return 0;
}
